const SOFTWARE_PLATFORM = {
    APP: 'App端',
    WEB: 'Web端',
    PC: 'PC端'
};

export const filterSoftwarePlatform = (platform = {}) => {
    const platformList = Object.keys(SOFTWARE_PLATFORM);

    const result = [];
    platformList.forEach(item => {
        if (platform[item]) {
            result.push(SOFTWARE_PLATFORM[item]);
        }
    });
    return result.join('、');
};

export const depthLookupSort = (treeData = [], fieldName) =>
    treeData.map((item = {}) => {
        const { children } = item;
        const result = { ...item };
        if (item.hasOwnProperty(fieldName)) {
            result[fieldName] = result[fieldName].sort();
        }

        if (Array.isArray(children) && children?.length) {
            result.children = depthLookupSort(children, fieldName);
        }
        return result;
    });
